package com.example.demo.web;

import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;

import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.example.demo.dao.UserDao;
import com.example.demo.entity.SysUser;

@RestController
@RequestMapping("/userController")
public class UserController {

	@Autowired
	private UserDao userDao;
	@RequestMapping(value="/helloword")
	public String HelloWord(){
		return "Hello SpringBoot2";
	}
	
	@RequestMapping(value="/tosave")
	public ModelAndView toSave(){
		System.out.println("------>tosave");
		return new ModelAndView("user.html");
	}
	
	@RequestMapping(value="dosave")
	public String doSave(HttpServletRequest reqeust){
		System.out.println("----->dosave");
		System.out.println(reqeust.getParameter("name"));
		SysUser user = new SysUser();
		String uuid = UUID.randomUUID().toString().replaceAll("-", "");
		user.setId(uuid);
		user.setName(reqeust.getParameter("name"));
		userDao.save(user);
		return "success";
	}
}
